package com.huifaapp.mall.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.blankj.utilcode.util.SPUtils;
import com.google.gson.Gson;
import com.huifaapp.mall.R;
import com.huifaapp.mall.adapter.TmallShopkeerDetailAdapter;
import com.huifaapp.mall.afinal.SPConstants;
import com.huifaapp.mall.api.ApiManager;
import com.huifaapp.mall.bean.Tmall_PreDetailBean;
import com.huifaapp.mall.uitils.AUniqueIdentifier;
import com.squareup.okhttp.Request;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by duanyu on 2017/12/29.
 * 店铺累积收益详情
 */

public class TmallShopkeepr_DetailFragment2 extends Fragment{
    private String PREDETAILURL2= ApiManager.BASE_NIUPAI_URL+"users/preDetail";
    private List<Tmall_PreDetailBean.DataBean.ListBean> tmall_preDetailList;
    private View mview;
    private RecyclerView fragemnt_tmalldetaila_recyclerView3;
    private EditText tmall_sgopeeper_detaila_edit_search_orderNo;
    private EditText tmall_sgopeeper_detaila_edit_search_startTime;
    private EditText tmall_sgopeeper_detaila_edit_search_endTime;
    private TextView tv_tmallsgopkeeper_detaila2_chaxun;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mview = inflater.inflate(R.layout.fragment_tmallsgopkeeper_detaila2, container, false);
        initView();
        initHttp();
        return mview;
    }

    private void initHttp() {
        Map<String,String>map=new HashMap<>();
        map.put("token", SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN));
        map.put("appId", AUniqueIdentifier.getDeviceId(getActivity()));
        map.put("preType","002");
        map.put("start","0");
        map.put("length","20");
        map.put("orderNo",tmall_sgopeeper_detaila_edit_search_orderNo.getText().toString());
        map.put("startTime",tmall_sgopeeper_detaila_edit_search_startTime.getText().toString());
        map.put("endTime",tmall_sgopeeper_detaila_edit_search_endTime.getText().toString());
        Log.e("累积收益收益接口",ApiManager.BASE_NIUPAI_URL+"users/preDetail"+"?token="+SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN)+"&appId="+AUniqueIdentifier.getDeviceId(getActivity())+"&preType="+"002"+"&start="+"0");
        OkHttpUtils.post().params(map).url(PREDETAILURL2).build().execute(new StringCallback() {
            @Override
            public void onError(Request request, Exception e) {

            }

            @Override
            public void onResponse(String response) {
                Gson gson=new Gson();
                Tmall_PreDetailBean tmall_preDetailBean = gson.fromJson(response, Tmall_PreDetailBean.class);
                Log.e("IIIIIIIIIIIII",response+"---------------------------------");
                tmall_preDetailList = new ArrayList<Tmall_PreDetailBean.DataBean.ListBean>();
                tmall_preDetailList.addAll(tmall_preDetailBean.getData().getList());
                TmallShopkeerDetailAdapter TmallShopkeerDetailAdapter=new TmallShopkeerDetailAdapter(tmall_preDetailList,getActivity());
                fragemnt_tmalldetaila_recyclerView3.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
                fragemnt_tmalldetaila_recyclerView3.setAdapter(TmallShopkeerDetailAdapter);
                TmallShopkeerDetailAdapter.setmdetailaItemclickListener(new TmallShopkeerDetailAdapter.detailaItemclickListener() {
                    @Override
                    public void detailaitemclick(View view, int position) {
//                        Toast.makeText(getActivity(),"ddddd",Toast.LENGTH_LONG).show();
                    }
                });
            }
        });
    }

    private void initView() {
        fragemnt_tmalldetaila_recyclerView3 = (RecyclerView) mview.findViewById(R.id.fragemnt_tmalldetaila_recyclerView2);
        tmall_sgopeeper_detaila_edit_search_orderNo = (EditText) mview.findViewById(R.id.tmall_sgopeeper_detaila_edit_search_orderNo2);
        tmall_sgopeeper_detaila_edit_search_startTime = (EditText) mview.findViewById(R.id.tmall_sgopeeper_detaila_edit_search_startTime2);
        tmall_sgopeeper_detaila_edit_search_endTime = (EditText) mview.findViewById(R.id.tmall_sgopeeper_detaila_edit_search_endTime2);
        tv_tmallsgopkeeper_detaila2_chaxun= (TextView) mview.findViewById(R.id.tv_tmallsgopkeeper_detaila2_chaxun);
        tv_tmallsgopkeeper_detaila2_chaxun.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                initHttp();
            }
        });
    }
}
